<template>
  <!-- 我的日程 -->
  <el-container>
    <el-header>
      <div class="left-panel">
        <!-- <el-button
          type="primary"
          icon="el-icon-plus"
          @click="add"
          v-auth-button="['add/mySchedule']"
        ></el-button> -->
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <el-select
            v-model="searchValue.leaveType"
            placeholder="请选择类型"
            style="width: 100%"
            clearable
          >
            <el-option
              :label="item.label"
              :value="item.value"
              v-for="item in leaveTypeList"
              :key="item.value"
            />
          </el-select>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="upsearch"
          ></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable ref="table" :apiObj="apiObj" row-key="id" stripe>
        <el-table-column label="ID" prop="id" width="50"></el-table-column>
        <el-table-column
          label="请假人"
          prop="username"
          width="200"
        ></el-table-column>
        <el-table-column
          label="开始时间"
          prop="startTime"
          width="200"
        ></el-table-column>
        <el-table-column
          label="结束时间"
          prop="endTime"
          width="200"
        ></el-table-column>
        <el-table-column
          label="时长"
          prop="duration"
          width="200"
        ></el-table-column>
        <el-table-column label="事由" prop="cause" min-width="200">
        </el-table-column>
        <el-table-column
          label="类型"
          prop="leaveTypeName"
          width="200"
        ></el-table-column>
        <el-table-column label="审批人" prop="toUsername" width="200">
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="250">
          <template #default="scope">
            <el-button-group>
              <el-button
                text
                type="primary"
                size="small"
                @click="table_show(scope.row, scope.$index)"
                >查看</el-button
              >
            </el-button-group>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>

  <save-dialog
    v-if="dialog.save"
    ref="saveDialog"
    @success="handleSaveSuccess"
    @closed="dialog.save = false"
    :userList="userList"
  ></save-dialog>
</template>

<script>
import saveDialog from './components/save'
export default {
  name: 'askForLeave',
  components: {
    saveDialog,
  },
  data () {
    return {
      dialog: {
        save: false,
      },
      apiObj: this.$API.attendance.getAskForLeaveList,
      userList: [],
      searchValue: {
        leaveType: '' //请假类型：1事假 2病假 3年假 4调休 5婚假 6丧假 7 产假
      },
      leaveTypeList: [{ value: 1, label: '事假' }, { value: 2, label: '病假' }, { value: 3, label: '年假' }, { value: 4, label: '调休' }, { value: 5, label: '婚假' }, { value: 6, label: '丧假' }, { value: 7, label: '产假' }]
    }
  },
  beforeMount () {
    this.getUserList()
  },
  methods: {
    // 获取用户
    async getUserList () {
      let param = {
        limit: 1000,
        page: 1
      }
      let { data } = await this.$API.user.getUserList.get(param)
      this.userList = data
    },
    //添加
    add () {
      this.dialog.save = true
      this.$nextTick(() => {
        this.$refs.saveDialog.open()
      })
    },

    //查看
    table_show (row) {
      this.$router.push({
        path: '/home/askForLeave/askForLeaveDetail',
        query: {
          id: row.id
        }
      })
    },
    //搜索
    upsearch () {
      this.$refs.table.upData(this.searchValue)
    },

    //本地更新数据
    handleSaveSuccess () {

      this.$refs.table.refresh()
    },

  }
}
</script>

<style>
</style>
